home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / unix / mp14tar.z / mp14tar / mpack / xmalloc.c < prev    next >
C/C++ Source or Header  |  1994-06-01  |  2KB  |  60 lines

  1. /* (C) Copyright 1993 by John G. Myers
  2.  * All Rights Reserved.
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software
  5.  * and its documentation for any purpose is hereby granted without
  6.  * fee, provided that the above copyright notice appear in all copies
  7.  * and that both that copyright notice and this permission notice
  8.  * appear in supporting documentation, and that the name of John G.
  9.  * Myers not be used in advertising or publicity pertaining to
  10.  * distribution of the software without specific, written prior
  11.  * permission.  John G. Myers makes no representations about the
  12.  * suitability of this software for any purpose.  It is provided "as
  13.  * is" without express or implied warranty.
  14.  *
  15.  * JOHN G. MYERS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  16.  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17.  * FITNESS, IN NO EVENT SHALL JOHN G. MYERS BE LIABLE FOR ANY SPECIAL,
  18.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  19.  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
  21.  * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  */
  23. #include <stdio.h>
  24. extern char *malloc(), *realloc();
  25.  
  26. char *xmalloc (size)
  27. int size;
  28. {
  29.     char *ret;
  30.  
  31.     if (ret = malloc((unsigned) size))
  32.       return ret;
  33.  
  34.     fprintf(stderr, "Memory exhausted\n");
  35.     exit(1);
  36. }
  37.  
  38.  
  39. char *xrealloc (ptr, size)
  40. char *ptr;
  41. int size;
  42. {
  43.     char *ret;
  44.  
  45.     /* xrealloc (NULL, size) behaves like xmalloc (size), as in ANSI C */
  46.     if (ret = !ptr ? malloc ((unsigned) size) : realloc (ptr, (unsigned) size))
  47.       return ret;
  48.  
  49.     fprintf(stderr, "Memory exhausted\n");
  50.     exit(1);
  51. }
  52.  
  53. char *strsave(str)
  54. char *str;
  55. {
  56.     char *p = xmalloc(strlen(str)+1);
  57.     strcpy(p, str);
  58.     return p;
  59. }
  60.